package com.feeyo.groundservice.composewidget.usage

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.Image
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import com.feeyo.groundservice.composewidget.R
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.composewidget.util.dimenToDp
import com.feeyo.groundservice.composewidget.util.dimenToSp
import com.feeyo.groundservice.composewidget.util.toComposeColor
import com.feeyo.groundservice.base_util.toast
import com.feeyo.groundservice.composewidget.view.slidebar.CustomSlideBar
import com.feeyo.groundservice.composewidget.view.slidebar.FixSlideBar
import com.feeyo.groundservice.composewidget.view.util.VerticalSpace

/**
 *作者：QLH on 2024-10-29
 *描述：滑块
 */
class SlideBarActivity : BaseComposeActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Column {
                Fix()
                VerticalSpace(R.dimen.d30.dimenToDp())
                Custom1()
                VerticalSpace(R.dimen.d30.dimenToDp())
                Custom2()
            }
        }
    }

    @Composable
    private fun Fix() {
        FixSlideBar(title = "滑动条", onDragEnd = {
            toast("滑动结束")
        })
    }

    @Composable
    private fun Custom1() {
        val beyond = remember { mutableStateOf(false) }
        val txtColor = animateColorAsState(
            if (beyond.value) R.color.white.toComposeColor()
            else R.color.blue_2E76EE.toComposeColor(), label = ""
        )
        CustomSlideBar(beyond = beyond, content = {
            Text(
                text = "滑动条",
                fontSize = R.dimen.d14.dimenToSp(),
                fontWeight = FontWeight.W400,
                color = txtColor.value,
                maxLines = 1,
                modifier = Modifier.align(Alignment.Center).basicMarquee(Int.MAX_VALUE)
            )
        },

            onDragEnd = {
                toast("滑动结束,失败")
                it.fail()
            })
    }

    @Composable
    private fun Custom2() {
        val beyond = remember { mutableStateOf(false) }
        val txtColor = animateColorAsState(
            if (beyond.value) R.color.white.toComposeColor() else R.color.blue_2E76EE.toComposeColor(),
            label = ""
        )
        CustomSlideBar(beyond = beyond, content = {
            Text(
                text = "滑动条",
                fontSize = R.dimen.d14.dimenToSp(),
                fontWeight = FontWeight.W400,
                color = txtColor.value,
                maxLines = 1,
                modifier = Modifier.align(Alignment.Center).basicMarquee(Int.MAX_VALUE)
            )
        },

            mask = {
                Box(
                    contentAlignment = Alignment.Center
                ) {
                    Image(
                        painter = painterResource(id = R.drawable.icon_slide_bar_arrow),
                        contentDescription = "",
                        contentScale = ContentScale.Inside,
                        modifier = Modifier.size(R.dimen.d23.dimenToDp())
                            .padding(end = R.dimen.d6.dimenToDp())
                    )
                    Text(
                        text = "滑动",
                        fontSize = R.dimen.d14.dimenToSp(),
                        fontWeight = FontWeight.W400,
                        color = R.color.white.toComposeColor(),
                        maxLines = 1,
                    )
                }

            },

            onDragEnd = {
                toast("滑动结束")
            })
    }
}